package tcards.android;

import models.HandCrewTcard;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

public class CrewFieldList extends LinearLayout {
	private GeneralFieldList mGeneralList;
	private GroupFieldList   mGroupList;
	private TextField        mLeaderName;
	private TextField        mContactInfo;
	private MultiField       mCrewNames;
	private PeopleFieldList  mPeopleList;
	
	public CrewFieldList(Context context) {
		this(context, null, 0);
	}

	public CrewFieldList(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public CrewFieldList(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		LayoutInflater li = LayoutInflater.from(context);
		addView(li.inflate(R.layout.crew_field_list, this, false));
		
		mGeneralList = (GeneralFieldList) findViewById(R.id.crewGeneralList);
		mGroupList   = (GroupFieldList)   findViewById(R.id.crewGroupList);
		mLeaderName  = (TextField)        findViewById(R.id.crewLeaderNameField);
		mContactInfo = (TextField)        findViewById(R.id.crewContactInfoField);
		mCrewNames   = (MultiField)       findViewById(R.id.crewNamesField);
		mPeopleList  = (PeopleFieldList)  findViewById(R.id.crewPeopleList);
	}
	
	public void setTcardFields(HandCrewTcard tcard) {
		mGeneralList.setTcardFields(tcard);
		mGroupList.setTcardFields(tcard);
		tcard.setLeaderName(mLeaderName.getTextValue());
		tcard.setContactInfo(mContactInfo.getTextValue());
		tcard.setCrewMembers(mCrewNames.getTextValue());
		mPeopleList.setTcardFields(tcard);
	}
	
	public void setListFields(HandCrewTcard tcard) {
		mGeneralList.setListFields(tcard);
		mGroupList.setListFields(tcard);
		mLeaderName.setTextValue(tcard.getLeaderName());
		mContactInfo.setTextValue(tcard.getContactInfo());
		mCrewNames.setTextValue(tcard.getCrewMembers());
		mPeopleList.setListFields(tcard);
	}
	
	public GeneralFieldList getGeneralList() {
		return mGeneralList;
	}
	
	public GroupFieldList getGroupList() {
		return mGroupList;
	}
	
	public TextField getLeaderName() {
		return mLeaderName;
	}
	
	public TextField getContactInfo() {
		return mContactInfo;
	}
	
	public MultiField getCrewNames() {
		return mCrewNames;
	}
	
	public PeopleFieldList getPeopleList() {
		return mPeopleList;
	}
}